import { getCookie } from '__assets/js/util'

const user = {
	state:{
		username:'',
		nickname:'',
		avatar:''
	},

	mutations:{
		SET_USER_INFO: (state,info) => {
			info = JSON.parse(info);
			state.username = info.username;
			state.nickname = info.nickname;
			state.avatar = info.avatar;
		}
	},

	actions:{
		setUserInfo({ commit }){
			let info = getCookie('userInfo');
			if(info){
				commit('SET_USER_INFO',info);
			}
		}
	}
}

export default user